//
//  TitleButton.m
//  新浪微博
//
//  Created by hbl on 16/2/18.
//  Copyright © 2016年 hbl. All rights reserved.
//

#import "TitleButton.h"
#define imgW 30
@implementation TitleButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = NSTextAlignmentRight;
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.adjustsImageWhenHighlighted = NO;
        self.imageView.contentMode = UIViewContentModeCenter;
        UIImage *backgroud = [UIImage imageNamed:@"navigationbar_filter_background_highlighted_os7"];
        backgroud = [backgroud resizableImageWithCapInsets:UIEdgeInsetsMake(backgroud.size.height * 0.5, backgroud.size.width * 0.5, backgroud.size.height * 0.5, backgroud.size.width * 0.5) resizingMode:UIImageResizingModeStretch];
        [self setBackgroundImage:backgroud forState:UIControlStateHighlighted];
    }
    return self;
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat h = contentRect.size.height;
    CGFloat w = contentRect.size.width - imgW;
    return  CGRectMake(x, y, w, h);

}

- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat x = contentRect.size.width - imgW;
    CGFloat y = 0;
    CGFloat h = contentRect.size.height;
    CGFloat w = imgW;
    return  CGRectMake(x, y, w, h);
}

@end
